package com.mouliu.base;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author liu.mou
 */
public class WaitNotify {
    static boolean flag = true;
    static Object lock = new Object();

//    public static void main(String[] args) throws InterruptedException {
//        Thread A = new Thread(new Wait(), "wait thread");
//        A.start();
//        TimeUnit.SECONDS.sleep(2);
//        Thread B = new Thread(new Notify(), "notify thread");
//        B.start();
//    }
    static class Wait implements Runnable{

        @Override
        public void run() {
            synchronized (lock){
                while (flag){
                    try {
                        System.out.println(Thread.currentThread() + " flag is true");
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println(Thread.currentThread() + " flag is false");
            }
        }
    }
    static class Notify implements Runnable{

        @Override
        public void run() {
            synchronized (lock){
                flag = false;
                lock.notifyAll();
                try {
                    TimeUnit.SECONDS.sleep(7);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args){
        List<String> appNameSet = new ArrayList<>();
        String[] ln = new String[]{"ab","abb","abbb","accc","adddd"};
        for (int i=0;i<ln.length;i++){
            if (!appNameSet.contains(ln[i])){
                appNameSet.add(ln[i]);
            }
        }
        System.out.println(appNameSet.size());
    }
}
